<?php
require_once './component/head.php';
if (!isset($_SESSION['uid'])) header('Location:./login.php');
require_once './component/drawer.php';
require_once './function/conn.php';
$i = 0;
?>
<script type="text/javascript">
    window.onload = function () {
        ScoreOnload();
    };
</script>

<div id="score_page" class="mdui-container drxs-page">
    <?php
    if ($_SESSION['utype'] == '管理员' || $_SESSION['utype'] == '教师') {
        $course_info = QueryDb("select * from drxs_course");
        $course_num = mysqli_num_rows($course_info);
        $student_info = QueryDb("select * from drxs_user where Type='学生'");
        $student_num = mysqli_num_rows($student_info);
        ?>
        <div id="add_score">
            <div class="mdui-card mdui-center">
                <div class="mdui-card-content">
                    <div class="mdui-typo"><h5>请输入以下基本信息，以添加新成绩。</h5></div>
                    <div class="mdui-divider"></div>
                    <form method="post" action="./function/function.php">
                        <div class="mdui-row" style="padding-top: 14px">
                            <div class="mdui-col-xs-6">
                                <label class="mdui-textfield-label">请选择课程（共 <?php echo $course_num; ?>门）</label>
                                <select class="mdui-select" size="3" name="add_score_course"
                                        mdui-select="{position: 'bottom'}">
                                    <option value="none" selected disabled>请选择课程</option>
                                    <?php
                                    while ($course = mysqli_fetch_array($course_info))
                                        echo '<option value=' . $course['CourseId'] . '> ' . $course['CourseId'] . ' - ' . $course['CourseName'] . '</option>';
                                    ?>
                                </select>
                            </div>
                        </div>
                        <div class="mdui-row" style="padding-top: 14px">
                            <div class="mdui-col-xs-6">
                                <label class="mdui-textfield-label">请选择学生（共<?php echo $student_num; ?>名）</label>
                                <select class="mdui-select" size="3" name="add_score_student"
                                        mdui-select="{position: 'bottom'}">
                                    <option value="none" selected disabled>请选择学生</option>
                                    <?php
                                    while ($student = mysqli_fetch_array($student_info))
                                        echo '<option value=' . $student['Id'] . '> ' . $student['Id'] . ' - ' . $student['Name'] . '</option>';
                                    ?>
                                </select>
                            </div>
                        </div>
                        <div class="mdui-textfield mdui-textfield-floating-label">
                            <label class="mdui-textfield-label">成绩</label>
                            <input class="mdui-textfield-input" name="add_score_score" type="text" required/>
                        </div>
                        <div class="mdui-card-actions">
                            <button type="button" class="mdui-btn mdui-ripple mdui-color-theme-accent mdui-float-right"
                                    id="add_score_btn"><a class="mdui-text-color-white">提交信息</a>
                            </button>
                            <button class="mdui-btn mdui-ripple mdui-color-theme-accent mdui-float-right" type="reset"
                                    mdui-tooltip="{content: '清除已填写的数据'}"><a class="mdui-text-color-white">重新填写</a>
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    <?php }
    if ($_SESSION['utype'] == '学生') {
        $table_color_1 = $_SESSION['table_color_1'];
        ?>
        <div id="query_score">
            <div class="mdui-table-fluid drxs-radius">
                <table id="all_score_table" class="mdui-table mdui-table-hoverable">
                    <thead>
                    <tr class="{$table_color_1}">
                        <th>课程id</th>
                        <th>课程名称</th>
                        <th>授课教师</th>
                        <th>课程成绩</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php
                    $all_score = QueryScore($_SESSION['uid']);
                    while ($score_info = mysqli_fetch_array($all_score)) :
                        if (($i++) % 2 == 0)
                            echo '<tr class=\'' . $_SESSION['table_color_2'] . '\'>';
                        else
                            echo '<tr class=\'' . $_SESSION['table_color_3'] . '\'>';
                        ?>
                        <td> <?php echo $score_info['CourseId']; ?> </td>
                        <td> <?php echo $score_info['CourseName']; ?> </td>
                        <td> <?php echo $score_info['TeacherName']; ?></td>
                        <td><?php echo $score_info['Score']; ?></td>
                        </tr>
                    <?php endwhile; ?>
                    </tbody>
                </table>
            </div>
        </div>
    <?php }
    if ($_SESSION['utype'] == '管理员' || $_SESSION['utype'] == '教师')
        echo "<div id='verify_score'></div>";
    ?>
</div>

<?php require_once './component/footer.php'; ?>
